package cn.wubo.file.preview.demo;

import cn.wubo.file.preview.storage.IFileStorage;
import cn.wubo.file.storage.core.FileInfo;
import cn.wubo.file.storage.core.FileStorageService;
import cn.wubo.file.storage.core.MultipartFileStorage;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class MinIOFileStorageImpl implements IFileStorage {

    @Resource
    FileStorageService fileStorageService;

    @Override
    public String save(byte[] bytes, String fileName) {
        FileInfo fileInfo = fileStorageService.save(new MultipartFileStorage(fileName, null, null, bytes).setAlias("minio-1").setPath("preview"));
        //FileInfo fileInfo = fileStorageService.save(new MultipartFileStorage(fileName, null, null, bytes).setAlias("local-1").setPath("preview"));
        return fileInfo.getId();
    }

    @Override
    public Boolean delete(String path) {
        return fileStorageService.delete(path);
    }

    @Override
    public byte[] getBytes(String path) {
        MultipartFileStorage file = fileStorageService.download(path);
        return file.getBytes();
    }

    @Override
    public void init() {

    }
}
